package fi.foyt.cs.api.json;

import java.util.Locale;

import org.json.JSONException;
import org.json.JSONObject;

import fi.foyt.cs.controller.LocaleController;
import fi.foyt.cs.persistence.domainmodel.task.GeneralTask;

public class GeneralTaskRenderer implements EntityRenderer<GeneralTask> {

  @Override
  public JSONObject getAsJson(Locale locale, GeneralTask entity) {
    LocaleController localeController = new LocaleController();
    
    JSONObject jsonObject = new JSONObject();
    
    try {
      jsonObject.put("id", entity.getId().getId());
      jsonObject.put("name", localeController.getLocalizedText(entity.getLocaleElementId(), locale));
    } catch (JSONException e) {
      throw new RenderingException(e);
    }

    return jsonObject;
  }
  
}
